﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using LeEdu.MODEL;
using LeEdu.BLL;

namespace LeEdu.Web
{
    // 注意: 有关启用 IIS6 或 IIS7 经典模式的说明，
    // 请访问 http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        /// <summary>
        /// 全局文件
        /// </summary>
        protected void Application_Start()
        {
            //上锁
            Application.Lock();
            //Application["Count"] = 0;//初始化变量，这个作用等同，都是将count设置为0。(网站的访问量)
            Application["OnLineCount"] = 0;  //在线人数的数量


            //解锁
            Application.UnLock();
            AreaRegistration.RegisterAllAreas();

           // WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
        /// <summary>
        /// 跟服务器打交道
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Session_Start(object sender, EventArgs e)
        { 
        //上锁
            Application.Lock();
            Session.Timeout = 30;

            ////访问量加1
            //Application["Count"] =Convert.ToInt32( Application["Count"]) + 1;
            //UserInfoBLL bll = new UserInfoBLL();

            //在线人数
            Application["OnLineCount"] =Convert.ToInt32( Application["OnLineCount"]) + 1;
            //解锁
            Application.UnLock();
        }
        protected void Session_End(object sender, EventArgs e)
        {
            //上锁
            Application.Lock();
            Session.Abandon();//当以一个会话结束后，注销该会话
            Application["OnLineCount"] = Convert.ToInt32(Application["OnLineCount"]) - 1;

            //解锁
            Application.UnLock();
        }
    }
}